<%--
 *  File:   ProdCollateEdit.jsp
 *  Desc:	ProdCollateEdit
 *
 *  Date		         Author		      Changes
 *  2006-4-18	  rogerwang		  Created
 *
 *  Copyright (C) 2000 - 2005 Oval Technologies, Inc.
 *  All rights reserved.
 *
 *  This software is the confidential and proprietary information of Oval
 *  Technologies, Inc. ("Confidential Information").  You shall not
 *  disclose such Confidential Information and shall use it only in
 *  accordance with the terms of the license agreement you entered into
 *  with Oval.
--%>
<%@ page import="java.text.*" %>
<%
  //init param
  String privilegeCode = "E0161";
  String strTableName = "v_prodcollateedit";
  String strModuleName = "CM";
	String contextPath = request.getContextPath();
%>
        <%@ include file="/inc/CommonHeader.inc" %>
        <%@ include file="/inc/OvalLocationDefault.inc" %>
		<%@ include file="/inc/Print.inc"%>
		<%@ include file="/rpt/ReportURL.inc" %>
		<%@ include file="/inc/NewCalendar.inc" %>

<html>
<head>
<title>ProdCollateEdit</title>
<PageFlow:CheckPageFlow pageName="p_prodcollateedit"/>
<%
    Vector totalsummary = (Vector)pageContext.getAttribute("totalsummary");
    if( totalsummary == null ) totalsummary = new Vector();
    
	String orgoptionvalue = (String)pageContext.getAttribute("orgoption");
	if(orgoptionvalue == null)orgoptionvalue = "1";
	
	

	Vector searchresults = (Vector)pageContext.getAttribute("searchresults");
	if(searchresults == null) searchresults = new Vector();
	String endday = (String)pageContext.getAttribute("endday");
	HashMap userinfo = (HashMap)session.getAttribute("userinfo");
	Integer  issalesman = (Integer) userinfo.get("issalesman");
	Integer  deptid = (Integer) userinfo.get("deptid");
	java.util.Calendar cal = java.util.Calendar.getInstance();      
	int day = cal.get(Calendar.DAY_OF_MONTH);
	String  strdeptid =deptid+"";
	String dateFormat = (String)session.getAttribute("dateformat");
	if(dateFormat==null)dateFormat = "yyyy-MM-dd";
%>
<%@ include file="/inc/CatchError.inc" %>
<%@ include file="/inc/SumDiv.inc" %>

<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<link rel="stylesheet" href="<%=contextPath%>/css/<%= strLanguageCode %>/main.css" type="text/css">
<script language="JavaScript" src="<%=contextPath%>/css/<%= strLanguageCode %>/script.js"></script>
<script language="JavaScript" src="<%=contextPath%>/js/ScriptLib.js"></script>
<script language="JavaScript" src="<%=contextPath%>/js/SummaryDivision.js"></script>
<script language="JavaScript" src="<%=contextPath%>/js/Calendar.js"></script>
<%@ include file ="/inc/NewCalendar.inc" %>
<script language="JavaScript">
window.onload= function(){
	if(document.cform.maptoproductstatusflag.value==1){
		document.cform.maptoproductstatusflag1.checked=true;
	}else{
		document.cform.maptoproductstatusflag1.checked=false;
	}
}
<%--  put your custom script here   --%>
function page_summary(actionvalue,orderbyname)
{
  if (document.cform.maptoproductstatusflag1.checked==true){
		document.cform.maptoproductstatusflag.value=1;
  }
    else{
		document.cform.maptoproductstatusflag.value=2;
  }	
  var editform = summaryPrepare(cform,actionvalue,orderbyname);
  if(!editform) return;
  editform.action = "ProdCollateEdit.jsp?<%= OvalTools.randomURL() %>&isgo=Y";
  editform.target = "_self";
  isRunning = true;
  editform.submit();
}
var selected_Idx;
function page_select(idx)
{
    selected_Idx=idx;
    window.open("<%=contextPath%>/phap/phap.datp/masterdata/kdm/ProductSelect.jsp?<%= OvalTools.randomURL() %>&status=41", "prdpop", "height=400, width=600,top=100,left=100,toolbar=n0, menubar=no, scrollbars=yes, resizable=no, location=no, status=no");
}
function page_select2(idx)
{
    selected_Idx=idx;
    page_reload();
}

function page_instantModify()
{
    var flag = confirm("<%= message.getMessageDesc("ARE_YOU_SURE_TO_UPDATE") %>");
    if(!flag)
  return;
    document.cform.actionname.value = "sync";
    document.cform.target="_self";
     isRunning = true;
     document.cform.submit();
}

function page_save()
{
 	var flag = confirm("<%= message.getMessageDesc("ARE_YOU_SURE_TO_COPY") %>");
	if(!flag) return;
    for(var i=0;i<<%=totalsummary.size()%>;i++)
    {
         var prodid = eval('document.cform.prodid'+i);
         var status = eval('document.cform.status'+i);
         var editprodcode = eval('document.cform.editprodcode'+i);
         var editprodid = eval('document.cform.editprodid'+i);
         if(!isEmpty(editprodid.value))
         {
            prodid.value = editprodid.value;
            status.value=10;
         }
    }

	document.cform.actionname.value = "save";
	document.cform.target="_self";
	isRunning = true;
	document.cform.submit();
}

function page_setproduct(id,umcode,prodcode,prodname)
{
    var editprodcode = eval('document.cform.editprodcode'+selected_Idx);
    var editprodid = eval('document.cform.editprodid'+selected_Idx);
    var editprodname = eval('document.cform.editprodname'+selected_Idx);
    editprodcode.value=prodcode;
    editprodid.value=id;
    editprodname.value = prodname;
}

function page_reload()
{
    var editprodcode = eval('document.cform.editprodcode'+selected_Idx);
    var editprodid = eval('document.cform.editprodid'+selected_Idx);

   editprodid.value = "";

   if(isEmpty(editprodcode.value))
   {
       editprodcode.value="";
       return;
   }

    var  datahandler = new  DataHandler() ;
    datahandler.add_params("languagecode" , cform.languagecode.value) ;
    datahandler.add_params("prodcode" ,editprodcode.value) ;
    datahandler.getResult("prodid" ,"document.cform.editprodid"+selected_Idx);
    datahandler.getResult("prodcode" ,"document.cform.editprodcode"+selected_Idx);
    datahandler.getResult("prdn" ,"document.cform.editprodname"+selected_Idx);
    datahandler.add_job("j_getproductbycode") ;
    datahandler.runDataHandler ();
}

function page_upload(){
	this.location.href = "<%= contextPath%>/phap/masterdata/spm/UploadEXL.jsp?first=ZZ&second=ZB01&third=Z0608&<%= OvalTools.randomURL() %>";
}

function page_download(){
	this.location.href = "<%= contextPath%>/phap/masterdata/spm/export/ExportProdCollate.jsp?<%= OvalTools.randomURL() %>";
}
</script>
</head>

<body>
<iframe id="reloadHandler" name="reloadHandler" style="display:none"></iframe>
<form name="cform" method="post" action="<%=contextPath%>/Dispatcher">
    <input type="hidden" name="pagename" value="p_prodcollateedit">
    <input type="hidden" name="actionname">
    <custom:hidden  property = "maptoproductstatusflag"/>
    <input type="hidden" name="numrows" value="<%=totalsummary.size()%>">
	<custom:hidden property="languagecode" scope="session"/>

<%--  page location   --%>
    <%@ include file="/inc/PageLocation.inc" %>
    
    <table width="100%" cellspacing="0" border="0" cellpadding="0">
<tr>       
        
        
          <%
                SimpleDateFormat formatter1 = new SimpleDateFormat ("yyyy-MM-dd");
                String str_date_end=formatter1.format(new Date());
                
              %>    
      <td><%= label.getLabelName("L_DatelastUpdated") + label.getLabelName("L_Colon") %>
	    
                <custom:text property="startdate"  dataType="date"  module="IMG" size="15" />
              <a onclick="javascript:c.show(this,'cform.startdate','yyyy-MM-dd');"><custom:button type="3" label="L_Asterisk" imgsrc="Time.gif" border="0"/></a>
              --
              <%if(pageContext.getAttribute("enddate")==null){%>
			  <custom:text property="enddate" dataType="date" dataFormatName="dateformat" module="IMG" size="15" />
			  <%}else{%>
			  <custom:text property="enddate"  dataType="date" dataFormatName="dateformat"  module="IMG"  size="15"/>
			  <%}%>
              <a onclick="javascript:c.show(this,'cform.enddate','yyyy-MM-dd');"><custom:button type="3" label="L_Asterisk" imgsrc="Time.gif" border="0"/></a>
              &nbsp;&nbsp;&nbsp;&nbsp;<%= label.getLabelName("L_InvalidProduct")+ label.getLabelName("L_Colon") %><custom:checkbox property="maptoproductstatusflag1" />
         </td>
       </tr>   
         
</table>




    <table width="100%" cellspacing="0" border="0" cellpadding="0">
      <tr>
<%--  search criteria  --%>
      </tr>
            
      <tr>
        <td>
          <table width="100%" border="0" cellspacing="0">
          	<tr>
	          <td class="summary_top" colspan="2" ></td>
	        </tr>
            <%@ include file="/inc/SummarySearch.inc" %>
          </table>
          </td>
      </tr>
      


      <tr>
        <td>
        <div style="width:100%;height=450;overflow=auto;">
          <table width="1700" border="1" cellpadding="0" bordercolorlight="#999999" bordercolordark="#FFFFFF" cellspacing="0" align="center">
<%--  summary title columns  --%>
            <tr class="deepblue-left">
            	<td width="8%" class="title_center">
            		<a href="javascript:page_summary('orderby','dtcode')"><%= label.getLabelName("L_DealerCode")%></a>
            	</td>
            	<td width="*%" class="title_center">
            		<a href="javascript:page_summary('orderby','dtname')"><%= label.getLabelName("L_DealerName") %></a>
            	</td>
            	<%if(orgoptionvalue.equals("2")){ %>
            	<td class="title_center" width="13%">
                    <a href="javascript:page_summary('orderby','prodcode')"><%= label.getLabelName("L_ProdCode")%></a>
                </td>
                <td class="title_center" width="15%">
                     <a href="javascript:page_summary('orderby','prodname')"><%= label.getLabelName("L_ProdName") %></a>
                </td>
            	<%}else{ %>
                <td class="title_center" width="15%">
                    <a href="javascript:page_summary('orderby','prodname')"><%= label.getLabelName("L_OriginProdName")%></a>
                </td>
                <td class="title_center" width="12%">
                     <a href="javascript:page_summary('orderby','spec')"><%= label.getLabelName("L_Spec1") %></a>
                </td>
                <%} %>
                <td class="title_center" width="18%">
                     <a href="javascript:page_summary('orderby','prodcode')"><%= label.getLabelName("L_MapToProduct")%></a>
                </td>
                 <td class="title_center" width="6%">
                     <a href="javascript:page_summary('orderby','prodstatus')"><%= label.getLabelName("L_MapToProduct")+label.getLabelName("L_Status")%></a>
                </td>
                <td class="title_center" width="21%">
                    <%= label.getLabelName("L_Edit") + label.getLabelName("L_ProdCode") %>
                </td>
                <td class="title_center" width="55">
                    <a href="javascript:page_summary('orderby','statusname')"><%= label.getLabelName("L_ActivityStatus") %></a>
                </td>
                <td class="title_center"><a href="javascript:page_summary('orderby','datelastupdated')"><%= label.getLabelName("L_DatelastUpdated") %></a></td>
                <td class="title_center"><a href="javascript:page_summary('orderby','employeename')"><%= label.getLabelName("L_Operater") %></a></td>
                
              </tr>
            <logic:iterate id="onerow" collection="<%= totalsummary %>" indexId="idx">
            <%
                String strClassType = new String("");
                    if(idx.intValue()%2 == 1)
                    {
                      strClassType = "td-listrom";
                    }else{
                      strClassType = "none";
                    }
            %>
              <tr  onMouseOver="this.className='tr-over'" onMouseOut="this.className='<%= strClassType %>'" class="<%= strClassType %>">
                <custom:hidden name="onerow" property="prodcollateid" colIndex="<%=idx%>"/>
                <td><custom:write name="onerow" property="dtcode" nbsp="true"/></td>
                <td><custom:write name="onerow" property="dtname" nbsp="true"/></td>
                <%if(orgoptionvalue.equals("2")){ %>
                <td><custom:write name="onerow" property="prodcode" nbsp="true"/></td>
                <td><custom:write name="onerow" property="prodname" nbsp="true"/></td>
                <%}else{ %>
                <td><custom:write name="onerow" property="prodname" nbsp="true"/></td>
                <td><custom:write name="onerow" property="spec" nbsp="true"/></td>
                <%} %>
                <td>
                    <custom:text name="onerow" property="prodcode1" readonly="true" style="border:0" size="15"/>
                    <custom:text name="onerow" property="prdn" colIndex="<%=idx%>" readonly="true" style="border:0" size="30"/>
                    <custom:hidden property="prodid" colIndex="<%=idx %>"/>
                </td>
                <td>
                    <custom:write name="onerow" property="prodstatus" dictType="Status"/>
                </td>
                <td>
                 <%String strFunName = "page_select2(" + idx + ")";%>
                    <custom:text  property="editprodcode" colIndex="<%=idx%>" onchange="<%=strFunName%>" size="15"/>
                    <custom:hidden  property="editprodid" colIndex="<%=idx%>" />
                    <a onclick='page_select(<%=idx%>)'><custom:button type="3" label="L_Asterisk" imgsrc="flash.gif" border="0"/></a>
                    <custom:text property="editprodname" colIndex="<%=idx %>" style="border:0" readonly="true" size="30"/>
                </td>
                <td class="td_center">
                    <custom:write name="onerow" property="statusname" nbsp="true"/>
                    <custom:hidden name="onerow" property="status" colIndex="<%=idx%>"/>
                </td>
                <td>&nbsp;<custom:write name="onerow" property="datelastupdated"/></td>
                <td>&nbsp;<custom:write name="onerow" property="employeename"/></td>
              </tr>
            </logic:iterate>
            <%@ include file="/inc/SummaryAction.inc" %>
          </table>
          </div>
            </td>
            </tr>
          <table width="100%" cellspacing="0" cellpadding="0">
            <tr><td class="summary_top"></td></tr>
            <tr>
              <td class="td_center">
              <%if(totalsummary.size() > 0){%>
                <a onclick="page_save();"><custom:button type="1" label="L_Submit" imgsrc="Modify.gif" border="0" style="width:60"/></a>
                <a onclick="page_instantModify();"><custom:button type="1" label="L_InstantModify" imgsrc="new.gif" border="0" style="width:60"/></a>
              <%}%>
              <custom:button label="L_Upload" styleClass="button1" style="width:80px;" onclick="page_upload()"/>
              <custom:button label="L_Download" styleClass="button1" style="width:80px;" onclick="page_download()"/>
              </td>
            </tr>
          </table>
        </td>
      </tr>
    </table>
</form>
</body>
</html>